package br.edu.senai.controller;

import br.edu.senai.model.Venda;

public class VendaDAO {
    Conexao conexao = new Conexao();

    public void salvar(Venda v) {

        if (v.getId() == null) {
            conexao.persist(v);
        } else {
            conexao.conectar();
            Venda pTemp = conexao.getEm().find(Venda.class, v.getId());
            conexao.desconectar();

            if (pTemp != null) {
                conexao.alterar(v);
            } else {
                conexao.persist(v);
            }
        }
    }

    public void remover(Venda v) {
        conexao.excluir(v);
    }
}
